package io.xxx.omni.oss

import java.sql.Driver
import java.sql.DriverManager
import java.util.*
import kotlin.concurrent.thread

class PolarDBTests {
}

fun main() {
    val start = System.currentTimeMillis()

    Class.forName(Driver::class.java.name)

    val t1 = thread {
        run0()
    }
    val t2 = thread {
        run0()
    }
    val t3 = thread {
        run0()
    }
    val t4 = thread {
        run0()
    }
    val t5 = thread {
        run0()
    }

    t1.join()
    t2.join()
    t3.join()
    t4.join()
    t5.join()

    println("耗时：" + (System.currentTimeMillis() - start))
}

private fun run0() {
    val url = "jdbc:mysql://pc-wz9ul0kf9y61u594p.rwlb.rds.aliyuncs.com:3306/trade"
    val username = "trade"
    val password = "Tradeuser123"
    val connection = DriverManager.getConnection(url, username, password)

    val sql = "insert into test(uuid) values(?)"
    val statement = connection.prepareStatement(sql)
    for (i in 1..10000) {
        statement.setString(1, UUID.randomUUID().toString().replace("-", ""))
        statement.execute()
    }
    statement.close()
    connection.close()
}